﻿/// <reference path="/Scripts/Base/jquery-1.7.1.js" />
/// <reference path="/Scripts/Base/jquery-ui-1.8.20.js" />

$(function () {
    var checked_img = new Image();
    var unchecked_img = new Image();

    function Init() {
        checked_img.src = "/Content/Images/dark-green-checked.png";
        unchecked_img.src = "/Content/Images/dark-green-unchecked.png";
        initCheckboxes();
    }; Init();

    function initCheckboxes() {
        //debugger;
        $("input[type=checkbox]").each(function () {
            $(this).hide();
            //debugger;
            if ($(this).is(":checked")) {
                $(this).siblings("img").first().attr("src", checked_img.src);
            } else {
                $(this).siblings("img").first().attr("src", unchecked_img.src);
            }
            $(this).siblings("img").first().removeClass("invisible");
        });
    };

    $(".checkbox-image").click(function () {
        //debugger;
        if ($(this).siblings("input[type=checkbox]").first().is(":checked")) {
            //jelenleg bekattintva
            $(this).attr("src", unchecked_img.src);
            $(this).siblings("input[type=checkbox]").first().attr('checked', false);
        } else {
            //jelenleg nincs bekattinva
            $(this).attr("src", checked_img.src);
            $(this).siblings("input[type=checkbox]").first().attr('checked', true);
        }
    });

    function filterFoldersByQuery() {
        //debugger;
        try {
            var searchString = $("#folder-filter-query").val().trim().toLowerCase();
            if (searchString != "") {
                $(".user-folder").each(function () {
                    if ($(this).attr("data-path").toLowerCase().indexOf(searchString) > 0) {
                        $(this).removeClass("invisible");
                    } else {
                        $(this).addClass("invisible");
                    }
                });
            }
        } catch (e) {
            alert(e);
        }
    }

    $("#btn-filter-folders").click(filterFoldersByQuery);

    $("#folder-filter-query").keyup(function (e) {
        if (e.keyCode == 13) {
            filterFoldersByQuery();
        }
    });

    $("#btn-folder-submit").click(function () {
        //$("input[type=checkbox]").each(function () { $(this).show(); });
    });


});